<template>
  <div class="pdf-box">
    <div class="head-box" @click.self="downloadPdf">
      <div class="head-left">
        <img src="./pdf.svg" alt="" width="50px" height="60px" />
      </div>
      <div class="head-right">
        <div class="head-right-top">
          {{ pdfData.direction }}
          <span @click.self="downPDF" class="head-right-download">下载</span>
        </div>
        <div class="head-right-bottom">
          <div>预览：{{ pdfData.seeNum }}</div>
          <div>下载：{{ pdfData.uploadNum }}</div>
        </div>
      </div>
    </div>
    <div class="footer-box" @click="downloadPdf">
      <div>
        {{ pdfData.name }}
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: ["pdfData", "showDelPdf"],
  methods: {
    downloadPdf() {
      let aTag = document.createElement("a");
      aTag.href = this.pdfData.pdf;
      aTag.target = "_blank";
      aTag.click();
      aTag = null;
    },
    downPDF() {
      let aTag = document.createElement("a");
      aTag.href = "http://localhost:3001/api/pdf/download?id=" + this.pdfData.id;
      aTag.click();
      aTag = null;
    },
    delPDF() {
      let id = this.pdfData.id;
      this.$axios
        .post("/pdf/del", {
          status: this.$store.state.user.userInfo.status,
          username: this.$store.state.user.userInfo.username,
          id,
        })
        .then((res) => {
          console.log(res);
          if (res.data.error === -1) {
            this.$message({
              type: "success",
              message: "删除成功",
            });
            this.$emit("refresh");
          } else {
            this.$message({
              type: "error",
              message: "删除失败",
            });
          }
        });
    },
  },
};
</script>

<style lang="less" scoped>
@keyframes bound {
  0% {
    transform: rotate(15deg);
  }
  100% {
    transform: rotate(-15deg);
  }
}
.pdf-box {
  border-radius: 5px;
  width: 250px;
  height: 120px;
  background-color: rgba(0, 0, 0, 0.05);
  color: #333;
  margin: 8px;
  position: relative;
  .delPDF {
    width: 23px;
    height: 23px;
    border-radius: 5px;
    background-color: red;
    color: #fff;
    text-align: center;
    line-height: 23px;
    font-size: 1000;
    position: absolute;
    z-index: 9;
    right: 0;
    top: 0;
    transform: rotate(15deg);
    animation: bound linear 0.1s infinite alternate-reverse;
    cursor: pointer;
  }
  .head-box {
    padding: 7px;
    display: flex;
    width: 200px;
    // background-color: rgba(0, 0, 0, 0.05);
    .head-left {
      font-size: 0px;
      margin-right: 5px;
    }
    .head-right {
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      .head-right-top {
        margin-top: 4px;
        text-align: left;
        font-size: 19px;
      }
      .head-right-download {
        font-size: 13px;
        color: rgba(0, 0, 0, 0.3);
        margin-left: 8px;
        cursor: pointer;
      }
      .head-right-bottom {
        display: flex;
        color: rgba(0, 0, 0, 0.3);
        font-size: 13px;
        div {
          margin-right: 8px;
        }
      }
    }
  }
  .footer-box {
    text-align: center;
    padding: 3px;
    font-size: 13px;
  }
}
</style>
